﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DBUtility;
using System.Data.SqlClient;

public partial class BasicBase_SocLinke_SocLinkeEdit : System.Web.UI.Page
{
    public String Result = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (PublicFunction.GetRequstQueryString(Request, "depid") != "")
        {
            string sortid=PublicFunction.GetRequstQueryString(Request, "sort");
            if(sortid=="all")
                sortid="";
            Result=Banding(PublicFunction.GetRequstQueryString(Request, "depid"), sortid, "", "", "", PublicFunction.GetRequstQueryString(Request, "type"));
        }
        if (PublicWeb.IsSubDelete(Request))
        {
            SQLHelper db = new SQLHelper();
            db.SqlExec("delete from SocLinke where INFOID='" + PublicFunction.GetRequstQueryString(Request, "id") + "'");
            db.SqlExec("delete from SocProp where SocLinkeID='" + PublicFunction.GetRequstQueryString(Request, "id") + "'");
        }
            
    }



    
    protected void Button1_Click(object sender, EventArgs e)
    {
        Result = Banding(PublicFunction.GetRequstForm(Request, "dep"), PublicFunction.GetRequstForm(Request, "sort01"), PublicFunction.GetRequstForm(Request, "InfoName"), PublicFunction.GetRequstForm(Request, "ProName"), PublicFunction.GetRequstForm(Request, "proCount"), "2");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("SocLinkeAdd.aspx");
    }

    String Banding(String dep, string sortID, string InfoName, string ProName, string proCount,string type)
    {
        String r = "";
        SQLHelper db = new SQLHelper();
        SqlParameter[] parameters = {
                new SqlParameter("@depid", SqlDbType.VarChar, 20),
                new SqlParameter("@SortID", SqlDbType.VarChar, 5),
                new SqlParameter("@InfoName", SqlDbType.VarChar, 50),
                new SqlParameter("@procName", SqlDbType.VarChar, 50),
                new SqlParameter("@procCount",SqlDbType.VarChar,10),
                new SqlParameter("@type",SqlDbType.VarChar,4)
            };

        parameters[0].Value = dep;
        parameters[1].Value = sortID;
        parameters[2].Value = InfoName;
        parameters[3].Value = ProName;
        parameters[4].Value = proCount;
        parameters[5].Value = type;
        string temp = "";
        int n = 1;
        DataTable dt = db.GetDatatableProcExcut("SocList", parameters);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            
            r += "<tr  class='grid_item' style=\" height:20px; \">\n";
            if (!temp.Equals(dt.Rows[i]["SORTNAME"].ToString().Trim()))
            {
                temp = dt.Rows[i]["SORTNAME"].ToString().Trim();
                r=r.Replace("{RowSpan}", n.ToString());
                n = 1;
                r += "<td width=\"70\" rowspan=\"{RowSpan}\" align=\"center\" valign=\"middle\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["SORTNAME"].ToString().Trim() + "</td>\n";
            }
            else
                n++;
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["InfoName"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["TelPhone"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["linkPeaple"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["Fax"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["Address"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["ProcContent"].ToString().Trim() + "</td>\n";
            r += "<td align=\"left\" style=\" height:20px; border-right-style:dotted; border-right-color:#cee7f7; border-right-width:1px; \">" + dt.Rows[i]["mark"].ToString().Trim() + "</td>\n";
            if (dt.Rows[i]["userID"].ToString().Trim() == Context.User.Identity.Name)
                r += "<td style=\" height:20px; \"><a href='SocLinkeEdit.aspx?act=edit&infoid=" + dt.Rows[i]["INFOID"].ToString().Trim() + "'>编辑</a>|<a href='#' onclick=\"javascript:deleteCheck('" + dt.Rows[i]["INFOID"].ToString().Trim() + "','" + dt.Rows[i]["InfoName"].ToString().Trim() + "')\">删除</a></td>\n";
            else
                r += "<td style=\" height:20px; \"><a href='SocLinkeEdit.aspx?act=view&infoid=" + dt.Rows[i]["INFOID"].ToString().Trim() + "'>查看</a></td>\n";
            r += "</tr>";
        }
        r = r.Replace("{RowSpan}", n.ToString());
            return r;
    }
    public String GetDepartmentid()
    {
        SQLHelper db = new SQLHelper();
        String dep = db.GetDataTableBySqlStr("SELECT DepartmentID  FROM [Account_Users] where userid='" + Context.User.Identity.Name + "'").Rows[0][0].ToString();
        if (dep.Substring(4, 1) == "0")
            return dep.Substring(0, 4) + "000";
        else
            return dep;
    }
}
